package com.clock.shop.repository;

import com.clock.shop.domain.ShopComment;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<ShopComment, Long> {
    //计算店铺平均分
    @Query("select avg(commentRate) from ShopComment where shopId = :shopId")
    float findAverageCommentRateByShopId(@Param("shopId") Long shopId);

    //按评分排序得到店铺id列表
    @Query("select distinct shopId from ShopComment group by shopId order by avg(commentRate) desc")
    List<Long> findTopShopIdsByAverageRating();
}
